<template>
	<div class="content">
		<Table stripe :columns="columns" :data="configList" ref="table" :loading="loading"></Table>
		<Modal v-model="modal1" title="修改配置" width='50%' :mask-closable="false">
			<Form :label-width="100" inline>
				<FormItem label="存储地址KEY" prop="addressStoreKey">
					<Input class="w-50" v-model="edit.addressStoreKey" placeholder="请输入存储地址KEY" />
				</FormItem>
				<FormItem label="币种ID" prop="coinId">
					<Input class="w-50" v-model="edit.coinId" placeholder="请输入直推实名认证用户数量" disabled/>
				</FormItem>
				<FormItem label="ETH/ERC20/OMNI归集地址" prop="collectAddress">
					<Input class="w-50" v-model="edit.collectAddress" placeholder="请输入ETH/ERC20/OMNI归集地址" />
				</FormItem>
				<FormItem label="最低归集数量" prop="collectLowerNum">
					<Input class="w-50" v-model="edit.collectLowerNum" placeholder="请输入最低归集数量" />
				</FormItem>
				<FormItem label="确认个数" prop="confirms">
					<Input class="w-50" v-model="edit.confirms" placeholder="请输入确认个数" />
				</FormItem>
				<FormItem label="ERC20智能合约地址" prop="contractAddress">
					<Input class="w-50" v-model="edit.contractAddress" placeholder="请输入ERC20智能合约地址" />
				</FormItem>
				<FormItem label="上次扫描的区块高度KEY" prop="lastBlockKey">
					<Input class="w-50" v-model="edit.lastBlockKey" placeholder="请输入上次扫描的区块高度KEY" />
				</FormItem>
				<FormItem label="ERC20精度" prop="myPrecision">
					<Input class="w-50" v-model="edit.myPrecision" placeholder="请输入ERC20精度" disabled />
				</FormItem>
				<FormItem label="币种名称" prop="name">
					<Input class="w-50" v-model="edit.name" placeholder="请输入币种名称" />
				</FormItem>
				<FormItem label="omni令牌ID：USDT为31 测试币为1" prop="omniType">
					<Input class="w-50" v-model="edit.omniType" placeholder="请输入omni令牌ID" />
				</FormItem>
				<FormItem label="节点服务器IP" prop="rpcIp">
					<Input class="w-50" v-model="edit.rpcIp" placeholder="请输入节点服务器IP" />
				</FormItem>
				<FormItem label="rpc密码：以太坊不用填写" prop="rpcPass">
					<Input class="w-50" v-model="edit.rpcPass" placeholder="请输入rpc密码" />
				</FormItem>
				<FormItem label="节点服务器端口" prop="rpcPort">
					<Input class="w-50" v-model="edit.rpcPort" placeholder="请输入节点服务器端口" />
				</FormItem>
				<FormItem label="rpc用户名：以太坊不用填写" prop="rpcUser">
					<Input class="w-50" v-model="edit.rpcUser" placeholder="请输入rpc用户名" />
				</FormItem>
				<FormItem label="总钱包地址" prop="supperAddress">
					<Input class="w-50" v-model="edit.supperAddress" placeholder="请输入总钱包地址" />
				</FormItem>
				<FormItem label="ETH总钱包地址密码" prop="supperPassword">
					<Input class="w-50" v-model="edit.supperPassword" placeholder="请输入ETH总钱包地址密码" />
				</FormItem>
				<FormItem label="技术类型" prop="type">
					<Input class="w-50" v-model="edit.type" placeholder="请输入技术类型" disabled />
				</FormItem>
				<FormItem label="ETH用户钱包密码" prop="userPass">
					<Input class="w-50" v-model="edit.userPass" placeholder="请输入ETH用户钱包密码" />
				</FormItem>
				<FormItem label="钱包账户前缀（BTC/OMNI必填）" prop="walletAccountAddressPrefix">
					<Input class="w-50" v-model="edit.walletAccountAddressPrefix" placeholder="请输入钱包账户前缀" />
				</FormItem>
				<FormItem label="是否归集" prop="collect">
					<Input class="w-50" v-model="edit.collect" placeholder="请输入true或false" />
				</FormItem>
			</Form>
			<div slot="footer">
				<Button type="text" size="large" @click="modal1 = false;">取消</Button>
				<Button type="primary" size="large" @click="editSubmit">确定</Button>
			</div>
		</Modal>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				pageSize: 1000,
				configList: [],
				modal1: false,
				loading: true,
				edit: {
					levelId: '',
					pushNum: '',
					layer: '',
					profitRatio: '',
				},
				rules: {
					pushNum: [{
						required: true,
						message: '直推实名认证用户数量不能为空',
						trigger: 'blur',
					}],
					layer: [{
						required: true,
						message: "节内的团队人数不能为空",
						trigger: "blur"
					}],
					profitRatio: [{
						required: true,
						message: "手续费百分比不能为空",
						trigger: "blur"
					}],
				},
				columns: [{
						title: '币种名称',
						key: 'name',
						align: 'center',
					},
					{
						title: '节点服务器IP',
						key: 'rpcIp',
						align: 'center',
					},
					{
						title: '节点服务器端口',
						key: 'rpcPort',
						align: 'center',
					},
					{
						title: '技术类型',
						key: 'type',
						align: 'center',
					},
					{
						title: '操作',
						key: 'action',
						align: 'center',
						render: (h, params) => {
							return h('div', [
								h(
									'Button', {
										props: {
											type: 'primary',
											size: 'small',
										},
										style: {
											marginRight: '5px'
										},
										on: {
											click: () => {
												this.modal1 = true;
												this.axios.get('/admin/settings/coin').then(res => {
													if(res.data.code == 200) {
														this.edit = res.data.data[params.index];
													}
												})
											}
										}
									},
									'编辑'
								),
							])
						}

					}
				]
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			});
			this.getConfig(); // 其他配置查询
		},
		methods: {
			getConfig() { // 其他配置查询
				this.axios.get('/admin/settings/coin').then(res => {
					if(res.data.code == 200) {
						this.configList = res.data.data;
						this.loading = false;
					}
				})
			},
			editSubmit() {
				let params = this.qs.stringify({
					id: this.edit.id,
					name: this.edit.name,
					type: this.edit.type,
					coinId: this.edit.coinId,
					rpcIp: this.edit.rpcIp,
					rpcPort: this.edit.rpcPort,
					rpcUser: this.edit.rpcUser,
					rpcPass: this.edit.rpcPass,
					confirms: this.edit.confirms,
					lastBlockKey: this.edit.lastBlockKey,
					walletAccountAddressPrefix: this.edit.walletAccountAddressPrefix,
					sync: this.edit.sync,
					omniType: this.edit.omniType,
					supperAddress: this.edit.supperAddress,
					userPass: this.edit.userPass,
					supperPassword: this.edit.supperPassword,
					contractAddress: this.edit.contractAddress,
					myPrecision: this.edit.myPrecision,
					collectAddress: this.edit.collectAddress,
					transfer: this.edit.transfer,
					addressStoreKey: this.edit.addressStoreKey,
					collectLowerNum: this.edit.collectLowerNum,
					collect: this.edit.collect
				})
				this.axios.put('/admin/settings/coin', params).then(res => {
					if(res.data.code == 200) {
						this.$Message.info(res.data.msg);
						this.modal1 = false;
						this.getConfig();
					}
				}).catch(err => {
					this.$Message.info('系统错误');
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.p-10 {
		padding-top: 0 !important;
		padding-left: 50px !important;
	}
	
	.w50 {
		width: 50px !important;
	}
	
	.w25 {
		width: 25px !important;
	}
	
	.w120 {
		width: 120px !important;
	}
	
	.mar {
		margin-left: 5px;
	}
	
	.pl-100 {
		padding-left: 100px;
	}
	
	.w-50 {
		width: 100% !important;
	}
</style>